<template>
  <div class="demo-project-sidebar-wrapper">
    <router-link
      v-for="item in options"
      :key="item.key"
      :to="item.path"
      :class="{
        'menu-item': true,
        selected: selectedRoute(item)
      }"
      class="gap-1 flex justify-center items-center flex-col cursor-pointer w-full item"
    >
      <a-tooltip :title="item.label" placement="right">
        <Icon class="fz20" style="width: 50px" :icon="item.icon" />
      </a-tooltip>
      <span class="menu-label">{{ item.label }}</span>
    </router-link>
  </div>
</template>

<script lang="ts">
import { createVNode, defineComponent } from 'vue'
import { getRoot } from '@/root'
import * as icons from '@ant-design/icons-vue'
import { ERouterName } from '@/types'

interface IOptions {
  key: number
  label: string
  path:
    | string
    | {
        path: string
        query?: any
      }
  icon: string
}

const Icon = (props: { icon: string }) => {
  return createVNode((icons as any)[props.icon])
}

export default defineComponent({
  components: {
    Icon
  },
  name: 'Sidebar',
  setup() {
    const root = getRoot()
    const options = [
      { key: 5, label: '任务规划', path: '/' + ERouterName.TASK, icon: 'CalendarOutlined' },
      { key: 0, label: '实时数据', path: '/' + ERouterName.TSA, icon: 'TeamOutlined' },
      { key: 3, label: '媒体列表', path: '/' + ERouterName.MEDIA, icon: 'PictureOutlined' },
      { key: 4, label: '航线列表', path: '/' + ERouterName.WAYLINE, icon: 'NodeIndexOutlined' },
      { key: 7, label: '模型成果', path: '/' + ERouterName.MODEL, icon: 'GroupOutlined' }
    ]

    function selectedRoute(item: IOptions) {
      const path = typeof item.path === 'string' ? item.path : item.path.path
      return root.$route.path?.indexOf(path) === 0
    }

    function goHome() {
      root.$router.push('/' + ERouterName.MEMBERS)
    }

    return {
      options,
      selectedRoute,
      goHome
    }
  }
})
</script>

<style scoped lang="scss">
.demo-project-sidebar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: vw(68);
  border-right: 1px solid #4f4f4f;
  color: $text-white-basic;
  // flex: 1;
  overflow: hidden;

  .menu-item {
    height: vh(78);
    color: $text-white-basic;

    &.selected {
      background: linear-gradient(180deg, #0e171e, #509cfe);
      color: $primary;
    }

    &.disabled {
      pointer-events: none;
      opacity: 0.45;
    }

    .menu-label {
      height: 16px;
      font-size: 12px;
      font-weight: 400;
      text-align: left;
      color: #dbdbdb;
    }
  }

  .filling {
    flex: 1;
  }

  .setting-icon {
    font-size: 24px;
    margin-bottom: 24px;
    color: $text-white-basic;
  }
}

.ant-tooltip-open {
  border: 0;
}
.item {
  height: vh(100) !important;
  background-size: vw(68) vh(100) !important;
}
</style>
